
#include <BHBoxLayout>
#include <BVBoxLayout>
#include <BClass>

#include "PromptMenu.h"

PromptMenu::PromptMenu()
{
	_label = new BLabel();

	BVBoxLayout* vlayout = new BVBoxLayout(this);
	vlayout->addWidget(_label);
}
PromptMenu::~PromptMenu()
{

}

void PromptMenu::setSource(BSource* source)
{
	_source = source;
}
BSource* PromptMenu::source()
{
	return _source;
}

void PromptMenu::setItem(SourceFormat::Item* item)
{
	if (_item != item)
	{
		_item = item;
		BString text;
		if (_item)
		{
			BExp* exp = _item->exp;
			switch (exp->syntax)
			{
			case Syntax_Type:
			{
				if (const BClass* cls = _source->findClass(exp->type))
				{
					if (cls->isMeta())
						text << "type ";
					else
						text << "class ";
					text << exp->type;
				}
				else
				{
					text << exp->type;
				}
				break;
			}
			case Syntax_Decl:
				text << "type " << exp->type;
				break;
			case Syntax_Name:
				text << exp->type << ' ' << exp->name;
				break;
			case Syntax_Self:
				text << exp->type << ' ' << exp->name;
				break;
			case Syntax_Call:
				if (exp->type.empty())
					text << "void";
				else
					text << exp->type;
				text << ' ' << exp->name << ';';
				break;
			case Syntax_Function:
				if (exp->type.empty())
					text << "void";
				else
					text << exp->type;
				text << ' ' << exp->name << ';';
				break;
			case Syntax_Method:
				if (exp->type.empty())
					text << "void";
				else
					text << exp->type;
				text << ' ' << exp->name << ';';
				break;
			default:
				break;
			}
			if (item->errorText.size())
			{
				text << '\n' << item->errorText;
			}
		}
		_label->setText(text);
	}
}
SourceFormat::Item* PromptMenu::item() const
{
	return _item;
}
